package com.swt.dao.impl.S_impl;

import com.swt.dao.S_dao.GetSupportPersonalDao;
import com.swt.domain.Employee;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository(value = "S_getSupportPersonalDao")
public class GetSupportPersonalDaoImpl implements GetSupportPersonalDao {
    /*注入hibernateTemplate*/
    @Resource(name = "hibernateTemplate")
    private HibernateTemplate hibernateTemplate;

    @Override
    public List<Employee> getSupportPersonal(int clubid) {
        /*从数据库中取数据*/
        DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Employee.class);
        detachedCriteria.add(Restrictions.eq("employeeSupportpersonal", "是"));
        detachedCriteria.add(Restrictions.eq("employeeClubid",clubid));
        List<Employee> list = (List<Employee>)hibernateTemplate.findByCriteria(detachedCriteria);
        return list;
    }

    @Override
    public Employee getSupportPersonalById(int employeeId) {
        Employee employee = hibernateTemplate.get(Employee.class, employeeId);
        return employee;
    }
}
